package sokoban;

public class Seeker {

	private StringBuffer sb = new StringBuffer();
	private int i = 0;
	private boolean inMarker = false;
	private String start;
	private String end;
	
	public Seeker(String start, String end){
		this.start = start;
		this.end = end;
	}
	
	public String getMarkedText(){
		inMarker = false;
		return sb.toString();
	}
	
	public boolean isTextMarked(char c){
		if(inMarker){
			sb.append(c);
			if(isMarkerFound(end, c)){
				sb.setLength(sb.length()-end.length());
				return true;
			}
		}
		else if(isMarkerFound(start, c)){
			sb = new StringBuffer();
			inMarker = true;
		}
		return false;
	}

	private boolean isMarkerFound(String marker, char c){
		if(marker.charAt(i) == c){
			i++;
		}
		else{
			i=0;
		}
		if(marker.length() == i){
			i=0;
			return true;
		}
		return false;
	}
}
